﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}
<script>
    var keyValue = request('keyValue');
    var BeginDate = request("BeginDate");
    var EndDate = request("EndDate");
    var PlanId = request("PlanId");
    var SWeek = request("SWeek");
    var Weeks = request("Weeks");
    var Id = request('keyValue');
    // var WorkDetail = request('WorkDetail');
    var Year = request('Year');
    var ItemId = request('ItemId');
    var Dlst = "";
    var WorkDetail = "";
    $(function () {
        debugger; 
        initControl();
        GetPalnDetail(PlanId);
    });
    //初始化控件
    function initControl() {
        if (keyValue == "Result") {
            $(".form-button").attr("hidden", "hidden");
            $(".btn_1").removeAttr("hidden");
            SetForm();
            GetPalnDetail(PlanId);
        }
        if (!!keyValue && keyValue != "Result") {
            $("#Title").val(Title);
            $('#StartDate').val(BeginDate);
            $('#EndDate').val(EndDate);
            var Str = "第" + SWeek + "周开始——第" + parseInt(parseInt(SWeek) + parseInt(Weeks - 1)) + "周结束"
            $("#Weeks").val(Str);
        }
    }
    //删除表单
    function Delete(s) {
        $.currentIframe().Del(keyValue, 2);
        dialogClose();
    }

    function finishbtn() {
        dialogClose();
    }
    function BaseClick(ss) {

        if (ss == 0) {
            $("#panel2").attr("hidden", "hidden")
            $("#panel1").removeAttr("hidden");
            $("#CS1").attr("hidden", "hidden")

        }
        else if (ss == 1) {
            if (WorkDetail == "") {
                GetGrid();
            } else {

                GetGrid1(Dlst);
            }
            $("#panel1").attr("hidden", "hidden")
            $("#panel2").removeAttr("hidden");
            $("#CS1").removeAttr("hidden")
        }
    }
    function GetGrid() {
        if (ItemId != "") {
            PlanId = ItemId;
        }
        $gridTable = $("#gridTable1");
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_DeviceMaintanenceBussiness/GetPlanDeviceList?keyValue=" + PlanId,
            datatype: "json",
            height: 350,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "设备名称", name: "Name", index: "Name", width: 180, align: "center", sortable: false },
                { label: "设备编号", name: "Code", index: "Code", width: 180, align: "center", sortable: false },
                { label: "设备等级", name: "Level", index: "Level", width: 200, align: "center", sortable: false },
                { label: "设备类型", name: "Type", index: "Type", width: 200, align: "center", sortable: false }
            ],
            viewrecords: true,
            treeGrid: true,
            rownumbers: true,
        });
    }
    function GetGrid1(Dlst) {

        $gridTable = $("#gridTable1");
        $gridTable.jqGrid({
            datatype: "json",
            height: 350,
            autowidth: true,
            unwritten: false,
            colModel: [
                { label: "Id", name: "Id", hidden: true },
                { label: "设备名称", name: "Name", index: "Name", width: 180, align: "center", sortable: false },
                { label: "设备编号", name: "Code", index: "Code", width: 180, align: "center", sortable: false },
                { label: "设备等级", name: "Level", index: "Level", width: 200, align: "center", sortable: false },
                { label: "设备类型", name: "Type", index: "Type", width: 200, align: "center", sortable: false }
            ],
            viewrecords: true,
            treeGrid: true,
            rownumbers: true,
        });
        $("#gridTable1")[0].addJSONData(Dlst);
    }
    function GetPalnDetail(PlanId) { 
        if (ItemId != "") {
            PlanId = ItemId;
        }
        $.ajax({
            type: "GET",
            async: false,
            dataType: "json",
            url: "../../PropertyManage/CS_DeviceMaintanenceBussiness/GetPalnDetail?keyValue=" + PlanId + "&WorkDetail=" + WorkDetail,
            success: function (data) {

                $("#Content").val(data.WEntity.Memo);
                $("#Title").val(data.WEntity.Name);
                Dlst = data.DList;
            }
        });
    }
    function SetForm() {
       
        $.SetForm({
            url: "../../PropertyManage/CS_DeviceMaintanenceBussiness/GetPalnEntity?keyValue=" + PlanId + "&Year=" + Year + "&SWeek=" + SWeek,
            param: { keyValue: keyValue },
            success: function (data) {
                $('#StartDate').val(data.BeginTime);
                $('#EndDate').val(data.EndTime);
                var Str = "第" + data.Year + "周开始——第" + parseInt(parseInt(data.Year) + parseInt(data.Month-1)) + "周结束"
                $("#Weeks").val(Str);
            }
        })
    }

    function btn_delete() {
        var keyValue = $("#gridTable1").getGridParam('selrow');


        if (keyValue) {

            var obj = $("#gridTable1").jqGrid("getRowData");
            if (obj.length == 1) {
                dialogMsg('最少关联一台设备', 0);
                return false;
            }

            dialogConfirm('注：您确定要移除吗？该操作将无法恢复？', function (r) {
                if (r) {

                    $("#gridTable1").delRowData(keyValue);
                    var obj1 = $("#gridTable1").jqGrid("getRowData");
                    var DeviceListId = "";
                    for (var i = 0; i < obj1.length; i++) {
                        DeviceListId += obj1[i].Id;
                    }
                    $.currentIframe().ChangeWorkDetail(Id, DeviceListId);
                    dialogMsg("移除成功。", 1);
                }
            });

        } else {
            dialogMsg('请选择需要移除的数据！', 0);
        }
    }
</script>
<div>
    <ul class="nav nav-tabs" style="background-color:#f6f8f8;">
        <li class="active" onclick="BaseClick(0)">
            <a href="#panel1" data-toggle="tab">计划详情</a>
        </li>
        <li onclick="BaseClick(1)">
            <a href="#panel2" data-toggle="tab">关联设备</a>
        </li>

    </ul>
</div>
<div class="tab-pane active" id="panel1">
    <table class="form">
        <tr>
            <td class="formTitle">项目标题</td>
            <td class="formValue" colspan="3">
                <input id="Title" type="text" readonly class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">项目起止</td>
            <td class="formValue" colspan="3">
                <input id="Weeks" type="text" readonly class="form-control" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">开始日期</td>
            <td class="formValue" colspan="3">
                <input id="StartDate" type="text" class="form-control  " readonly />
            </td>
        </tr>
        <tr>
            <td class="formTitle">结束日期</td>
            <td class="formValue" colspan="3">
                <input id="EndDate" type="text" class="form-control  " readonly />
            </td>

        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 10px;">日程内容</th>
            <td class="formValue" colspan="3">
                <textarea id="Content" class="form-control" readonly style="height: 170px;"></textarea>
            </td>
        </tr>

    </table>

</div>

<div class="tab-pane" id="panel2" hidden>
    <div class="titlePanel">
        <table id="gridTable1"></table>

    </div>
    @*<div class="toolbar" id="CS1" style=" position: absolute; top: 10px; right: 20px;" hidden>
            <a id="lr-deleteField" class="btn btn-danger btn-xs" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;移除</a>
        </div>*@
</div>
<div class="form-button" id="wizard-actions">
    <a id="btn_delete" class="btn btn-danger" onclick="Delete();">删除</a>
    <a id="btn_finish" class="btn btn-info" onclick="finishbtn();">关闭</a>
</div>
<div class="form-button btn_1" hidden id="wizard-actions">
    <a id="btn_finish" class="btn btn-info" onclick="finishbtn();">关闭</a>
</div>

